#ifndef __VL53L0X_H
#define __VL53L0X_H

#include "vl53l0x_api.h"
#include "vl53l0x_platform.h"
#include "stm32g0xx.h"
//#include "cmsis_os.h"
#include <stdbool.h>
#define hal_delay_ms(x) osDelay(x)




extern VL53L0X_Dev_t multi_vl53l0x_dev[6];
void bsp_init(void);

typedef __packed struct
{
    uint8_t  adjustok;                    
    uint8_t  isApertureSpads;              //ApertureSpadsֵ
    uint8_t  VhvSettings;                  //VhvSettingsֵ
    uint8_t  PhaseCal;                     //PhaseCalֵ
    uint32_t XTalkCalDistance;             //XTalkCalDistanceֵ
    uint32_t XTalkCompensationRateMegaCps; //XTalkCompensationRateMegaCpsֵ
    uint32_t CalDistanceMilliMeter;        //CalDistanceMilliMeterֵ
    int32_t  OffsetMicroMeter;             //OffsetMicroMeterֵ
    uint32_t refSpadCount;                 //refSpadCountֵ
    
}_VL53L0X_adjust;


extern VL53L0X_RangingMeasurementData_t vl53l0x_data;

VL53L0X_Error vl53l0x_set_mode(VL53L0X_Dev_t *dev,uint8_t mode);
void vl53l0x_general_test(VL53L0X_Dev_t *dev);
void Show_GenTask_Message(void);

#define VL53L0X_Addr 0x52

#define VL53L0X_Xshut PIout(3)

#define USE_I2C_2V8  1

#define Default_Mode   0
#define HIGH_ACCURACY  1
#define LONG_RANGE     2
#define HIGH_SPEED     3

#define   LV_DISABLE(port, pin)             HAL_GPIO_WritePin(port ,pin,GPIO_PIN_RESET);
#define   LV_ENABLE(port, pin)              HAL_GPIO_WritePin(port ,pin,GPIO_PIN_SET);

typedef __packed struct
{
    FixPoint1616_t signalLimit;    
    FixPoint1616_t sigmaLimit;    
    uint32_t timingBudget;         
    uint8_t preRangeVcselPeriod ;  
    uint8_t finalRangeVcselPeriod ;
    
}mode_data;


extern mode_data Mode_data[];
extern uint8_t AjustOK;

VL53L0X_Error vl53l0x_init(VL53L0X_Dev_t *dev,uint8_t new_addr);
void print_pal_error(VL53L0X_Error Status);
void mode_string(uint8_t mode,char *buf);
void vl53l0x_start_measurement(void);
VL53L0X_Error vl53l0x_reset(VL53L0X_Dev_t *dev);

void vl53l0x_info(void);
void One_measurement(uint8_t mode);
void Show_Mode_Message(void);

void DBG_Read_ReferenceRegs(void);  //add.cj  ps:Test for read reference register
void DBG_Reset_All(void); //add.cj  ps:Test ResetAll Device
void DBG_VL_Init(void);

bool DBG_PowerOn_SetAdd(void);
#endif


